﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:markup="clr-namespace:Elysium.Markup"
                    xmlns:params="clr-namespace:Elysium.Parameters">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Themes/SharedResources.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <ControlTemplate x:Key="{x:Static MenuItem.SubmenuHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border x:Name="LayoutRoot"
                Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <Grid TextBlock.Foreground="{TemplateBinding Foreground}"
                  TextBlock.FontFamily="{TemplateBinding FontFamily}"
                  TextBlock.FontSize="{TemplateBinding FontSize}"
                  TextBlock.FontStretch="{TemplateBinding FontStretch}"
                  TextBlock.FontStyle="{TemplateBinding FontStyle}"
                  TextBlock.FontWeight="{TemplateBinding FontWeight}"
                  TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}"
                  TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}"
                  RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}"
                  Margin="{TemplateBinding Padding}"
                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"
                                      SharedSizeGroup="ContextMenuIconSizeGroup"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <ContentPresenter x:Name="IconHost"
                                  Grid.Column="0"
                                  ContentSource="Icon"
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Center"
                                  MinWidth="16" MinHeight="16"/>
                <ContentPresenter x:Name="HeaderHost"
                                  Grid.Column="1"
                                  ContentSource="Header"
                                  RecognizesAccessKey="True"
                                  Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(params:General.BoldPaddingValue), Mode=OneWay, Converter={StaticResource DoubleToThicknessConverter}, ConverterParameter='Left, Right'}"
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Center"/>
                <Polygon x:Name="ArrowGlyph"
                         Grid.Column="2"
                         Fill="{markup:ThemeResource NormalBrush}"
                         StrokeThickness="0"
                         Stretch="Uniform"
                         Margin="{TemplateBinding params:MenuItem.ArrowMargin}"
                         HorizontalAlignment="Right" VerticalAlignment="Center"
                         Width="{TemplateBinding params:MenuItem.ArrowSize}"
                         Height="{TemplateBinding params:MenuItem.ArrowSize}">
                    <Polygon.Points>
                        <PointCollection>
                            <Point X="0" Y="0"/>
                            <Point X="2" Y="2"/>
                            <Point X="0" Y="4"/>
                        </PointCollection>
                    </Polygon.Points>
                </Polygon>
                <Popup x:Name="PART_Popup"
                       Grid.Column="0" Grid.IsSharedSizeScope="True"
                       AllowsTransparency="True"
                       Focusable="False"
                       Placement="Right"
                       PlacementTarget="{Binding ElementName=LayoutRoot}"
                       IsOpen="{TemplateBinding IsSubmenuOpen}"
                       PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                       Tag="{DynamicResource {x:Static SystemParameters.MenuAnimationKey}}">
                    <Border x:Name="PopupRoot"
                            Tag="{DynamicResource {x:Static SystemParameters.DropShadowKey}}">
                        <Border Background="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBackground)}"
                                BorderBrush="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBorderBrush)}"
                                BorderThickness="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBorderThickness)}"
                                TextBlock.Foreground="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=Foreground}"
                                TextBlock.FontFamily="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontFamily}"
                                TextBlock.FontSize="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontSize}"
                                TextBlock.FontStretch="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontStretch}"
                                TextBlock.FontStyle="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontStyle}"
                                TextBlock.FontWeight="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontWeight}"
                                TextOptions.TextFormattingMode="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(TextOptions.TextFormattingMode)}"
                                TextOptions.TextRenderingMode="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(TextOptions.TextRenderingMode)}"
                                RenderOptions.ClearTypeHint="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(RenderOptions.ClearTypeHint)}"
                                SnapsToDevicePixels="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=SnapsToDevicePixels}">
                            <StackPanel IsItemsHost="True"
                                        KeyboardNavigation.DirectionalNavigation="Cycle"
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="Stretch"/>
                        </Border>
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="IconHost" Property="Visibility" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsSubmenuOpen" Value="True">
                <Setter TargetName="ArrowGlyph" Property="Fill" Value="{markup:ThemeResource AccentBrush}"/>
            </Trigger>
            <Trigger Property="IsSuspendingPopupAnimation" Value="True">
                <Setter TargetName="PART_Popup" Property="PopupAnimation" Value="None"/>
            </Trigger>
            <Trigger SourceName="PART_Popup" Property="Tag" Value="False">
                <Setter TargetName="PART_Popup" Property="PopupAnimation" Value="None"/>
            </Trigger>
            <DataTrigger Binding="{Binding ElementName=PopupRoot, Path=Tag}" Value="True">
                <Setter TargetName="PopupRoot" Property="Effect">
                    <Setter.Value>
                        <DropShadowEffect Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:General.ShadowBrush).(SolidColorBrush.Color)}"
                                          BlurRadius="4" ShadowDepth="2"
                                          Direction="315"
                                          Opacity="0.3"/>
                    </Setter.Value>
                </Setter>
                <Setter TargetName="PopupRoot" Property="Background" Value="{markup:ThemeResource TransparentBrush}"/>
                <Setter TargetName="PopupRoot" Property="Padding" Value="0,0,6,6"/>
            </DataTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    
</ResourceDictionary>